<?xml version="1.0" encoding="UTF-8" ?>
<!-- 
    This file is part of Microsoft Robotics Developer Studio Code Samples.
    Copyright (C) Microsoft Corporation.  All rights reserved.
    $File: ColorSensor.xslt $ $Revision: 2 $
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:accel="http://schemas.vexrobotics.com/2011/09/vexservice.accelerometer.html">
  <xsl:import href="/resources/dss/Microsoft.Dss.Runtime.Home.MasterPage.xslt" />

  <xsl:template match="/">
    <xsl:call-template name="MasterPage">

      <xsl:with-param name="title">
        <xsl:text>VEX Accelerometer Sensor</xsl:text>
      </xsl:with-param>
      <xsl:with-param name="serviceName">
        VEX Accelerometer
      </xsl:with-param>
      <xsl:with-param name="description">
        Provides access to the VEX Accelerometer.
      </xsl:with-param>


      <xsl:with-param name="head">
        <script language="javascript" type="text/javascript" src="/resources/VEXService.Y2011.M09/VEXService.config.Common.js"/>
        <script language="javascript" type="text/javascript">
          <xsl:text>
var pollingFrequency = 1000;
var timeStamp = "</xsl:text>
          <xsl:value-of select="/accel:VEXAccelerometerState/accel:TimeStamp"/>
          <xsl:text>";
</xsl:text>

          <![CDATA[
          
function onState(state)
{
    if (state.TimeStamp != timeStamp)
    {
      timeStamp = state.TimeStamp;
      document.all("timestampCell").innerText = timeStamp;
      
      document.all("XCell").innerText = state.X;
      document.all("YCell").innerText = state.Y;
      document.all("ZCell").innerText = state.Z;
    }
    readState(pollingFrequency);
}

function startPolling()
{
  setStateCompletion("onState");
  readState(pollingFrequency);
}

setTimeout("startPolling()", pollingFrequency);

          ]]>
        </script>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!--<xsl:output method="html"/>-->

  <xsl:template match="accel:VEXAccelerometerState">
    <form method="POST" action="" name="SetAccellForm">
      <input type="hidden" name="Action" value="VEXAccel" />
      <table width="100%" border="0" cellpadding="5" cellspacing="5">
        <tr>
          <th colspan="2">
            VEX Accelerometer
            <img src="/resources/VEXService.Y2011.M09/VEXService.config.Accelerometer.png"
                 align="right" alt="Accelerometer" width="125px" height="125px"/>
          </th>
        </tr>

        <tr class="even">
          <th width="20%">
            Name:
          </th>
          <td width="80%">
            <input type="text" name="Name" size="80">
              <xsl:attribute name="value">
                <xsl:value-of select="accel:Name"/>
              </xsl:attribute>
            </input>
          </td>
        </tr>
        <tr class="odd">
          <th width="20%">
            Has Range Jumper:
          </th>
          <td width="80%">
            <input id="State" type="checkbox" title="State">
              <xsl:attribute name="name">HasRangeJumper</xsl:attribute>
              <xsl:if test="accel:HasRangeJumper != 'false'">
                <xsl:attribute name="checked">checked</xsl:attribute>
              </xsl:if>
              <xsl:attribute name="value">1</xsl:attribute>
            </input>
          </td>
        </tr>

        <tr class="even">
          <th width="20%">
            X Sensor Port:
          </th>
          <td width="80%">
            <xsl:value-of select="accel:SensorPortX"/>
          </td>
        </tr>
        <tr class="odd">
          <th width="20%">
            Y Sensor Port:
          </th>
          <td width="80%">
            <xsl:value-of select="accel:SensorPortY"/>
          </td>
        </tr>
        <tr class="even">
          <th width="20%">
            Z Sensor Port:
          </th>
          <td width="80%">
            <xsl:value-of select="accel:SensorPortZ"/>
          </td>
        </tr>

        <tr class="odd">
          <th width="20%">
            X:
          </th>
          <td width="80%" id="XCell">
            <xsl:value-of select="accel:X"/>
          </td>
        </tr>
        <tr class="even">
          <th width="20%">
            Y:
          </th>
          <td width="80%" id="YCell">
            <xsl:value-of select="accel:Y"/>
          </td>
        </tr>
        <tr class="odd">
          <th width="20%">
            Z:
          </th>
          <td width="80%" id="ZCell">
            <xsl:value-of select="accel:Z"/>
          </td>
        </tr>

        <tr class="even">
          <th width="20%">
            TimeStamp:
          </th>
          <td width="80%" id="timestampCell">
            <xsl:value-of select="accel:TimeStamp"/>
          </td>
        </tr>
      </table>
      <td>
        <input id="Button2" type="reset" value="Reset" name="buttonReset" title="Reset Configuration"/>
        <input id="Button1" type="submit" value="Set Values" name="button_set_all" title="Set Values"/>
      </td>
    </form>
  </xsl:template>
</xsl:stylesheet>
